package com.lanou3g.ptp.grade.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.lanou3g.ptp.entity.GradeRole;
import com.lanou3g.ptp.grade.mapper.GradeRoleMapper;
import com.lanou3g.ptp.grade.service.GradeRoleService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class GradeRoleServiceImpl implements GradeRoleService {
    @Autowired
    private GradeRoleMapper gradeRoleMapper;
//  添加一个gradeRole
    @Override
    public void addGradeRole(GradeRole gradeRole) {
        gradeRole.setUpdateTime(new Date());
        gradeRole.setCreateTime(new Date());
        gradeRole.setStatus(0);
        gradeRoleMapper.addGradeRole(gradeRole);
    }
//   通过id删除
    @Override
    public void deleteById(Long id) {
        gradeRoleMapper.deleteById(id);
    }
//   通过id修改
    @Override
    public void updateById(GradeRole gradeRole) {
        gradeRole.setUpdateTime(new Date());
        gradeRoleMapper.updateById(gradeRole);
    }
//   查询所有
    @Override
    public List<GradeRole> findAll() {
        List<GradeRole> gradeRoles = gradeRoleMapper.findAll();
        return gradeRoles;
    }
//   通过id查找
    @Override
    public GradeRole findById(Long id) {
        GradeRole gradeRole = gradeRoleMapper.findById(id);
        return gradeRole;
    }
//   通过gradeId查找
    @Override
    public List<GradeRole> findByGradeId(Long gradeId) {
       List<GradeRole> gradeRoles= gradeRoleMapper.findByGradeId(gradeId);
       return gradeRoles;
    }

    @Override
    public List<GradeRole> findByStudentId(Long studentId) {
        List<GradeRole> roles= gradeRoleMapper.findByStudentId(studentId);
        return roles;
    }

    @Override
    public void deleteByGradeId(Long id) {
        gradeRoleMapper.deleteByGradeId(id);
    }
}
